﻿<!doctype html>
<html>

<head>
    <title></title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=yes" />
    <meta name="format-detection" content="email=no" />
    <script type="text/javascript" src="/Utility/CoreScripts/jquery.js?ver={$version}"></script>
    <vt:if var="domain" value="" compare="!=">
        <script type="text/javascript">
            document.domain = '{$domain}';          
        </script>
    </vt:if>
    <style type="text/css">
        .txt {
            text-align: center;
            margin: 30px;
            display: none;
        }

        a {
            color: #333;
            text-decoration: none;
            line-height: 35px;
        }
    </style>
</head>

<body>
    <p>
    </p>
    <div id="loading" class="txt" appid="{$WeixinpubAPPID}" returl="{$WeixinpubReturl}" orgid="{$org.Org_id}">
        <a href="" id="url">正在登录...<br />
            无法正常跳转，请点击 </a>
    </div>
    <div id="error" class="txt">
        此页面仅限在微信中访问</div>
    <script type="text/javascript">
        //格式化字符串
        String.prototype.format = function (args) {
            var result = this;
            for (var i = 0; i < arguments.length; i++) {
                result = result.replace(eval('/\\{' + i + '\\}/g'), arguments[i]);
            }
            return result;
        }
        //是否处于微信中
        function isWeiXin() {
            var ua = window.navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                return true;
            } else {
                return false;
            }
        }
        (function () {
            //获取前缀，主要用来判断是http还是https
            var prefix = function (returl) {
                var arr = "http://|https://".split("|");
                var ispass = false;
                for (var t in arr) {
                    if (arr[t].length > returl.length) continue;
                    if (returl.indexOf(arr[t]) == 0) {
                        ispass = true;
                        break;
                    }
                }
                //return !ispass ? "http://" + returl : returl;
                return returl;
            }
            var tag = $("#loading");
            var appid = tag.attr("appid"); //appid
            var returl = prefix(tag.attr("returl")) + "/mobile/weixinpublogin.ashx"; //回调域	

            var orgid = tag.attr("orgid"); 	//当前机构id
            var target = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state={2}#wechat_redirect";
            target = target.format(appid, encodeURIComponent(returl), orgid);
            $("#url").attr("href", target);
            $("#url").click(function () {
                var href = $(this).attr("href");
                window.location.href = target;
            });
        })();

    </script>
    <script type="text/javascript">
        (function () {
            if (isWeiXin()) {
                $("#loading").show();
                //登录微信
                document.getElementById("url").click();
                var target = $("#url").attr("href");
                window.location.href = target;
                setInterval(function () {
                    var target = $("#url").attr("href");
                    window.location.href = target;
                }, 1000);
            }
            if (!isWeiXin()) $("#error").show();
        })();
    </script>
</body>

</html>